package org.xt.service;

import java.util.Date;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.trans.Atom;
import org.nutz.trans.Trans;
import org.xt.entity.Permission;
import org.xt.entity.RolePermission;

@IocBean(name="permissionService")
public class PermissionService {
	@Inject
	private Dao dao;
	
	public Permission add(Permission p){
		p.setCreateTime(new Date());
		p.setUpdateTime(new Date());
		return dao.insert(p);
	}
	
	public int delete(int id){
		Trans.exec(new Atom() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				dao.delete(Permission.class, id);
				Sql sql = Sqls.create("DELETE FROM tb_role_permission WHERE permissionId=@id");
				sql.params().set("id", id);
				dao.execute(sql);
			}
		});
		return 1;
	}
}
